///////////////////////////////////////////////////////////////////////////

#ifndef _MP3TRACK_H_
#include "mp3track.h"
#endif

#ifndef _TIMER_H_
#include "timer.h"
#endif

#include <iostream>
#include <fstream>

///////////////////////////////////////////////////////////////////////////



int main(int argc, char** argv)
{
    MP3Track track("02-example.mp3");

    size_t prevTime = Timer::GetCurrTime();
    size_t totalMillisec = 0;
    size_t totalSeconds = 0;

    std::ofstream out1("out1.txt");
    std::ofstream out2("out2.txt");


    // Read 1024 samples of a track
    while ( track.Read() )
    {
        track.Play();

        // Try to detect beat
        std::cout << totalSeconds << "      " << (track.DetectBeatFreq() ? "beat" : ".") << std::endl;

        out1 << totalSeconds << "      " << (track.DetectBeat() ? "beat" : ".") << std::endl;
        out2 << totalSeconds << "      " << (track.DetectBeatFreq() ? "beat" : ".") << std::endl;

        out1.flush();
        out2.flush();

        //  sleep for  [[[ 1 second / (44000 SamplesPerSecond / 1024Samples) ) ]]]
        Timer::Sleep(22);
        

        totalSeconds = totalMillisec / 1000;
        totalMillisec += Timer::GetCurrTime() - prevTime;
        prevTime = Timer::GetCurrTime();
    }

    return 0;
}